<?php
	namespace Admin\Controller;

	class UserController extends CommonController{

		public $like='';

		public function index(){

			$userModel=D('User');
			$this->like=$_GET['like'];
			if(empty($this->like))
			{
				$total=$userModel->count();
				$page= new \Think\Page($total,3);
				$page->setConfig('prev','上一页');
				$page->setConfig('next','下一页');

				$page_str = $page->show();

				$limit=$page->firstRow.','.$page->listRows;

				$list=$userModel->getAll($limit);
			}else{
				$where['name']=array('like','%'.$this->like.'%');
				$total=$userModel->where($where)->count();
				$page= new \Think\Page($total,3);
				$page->setConfig('prev','上一页');
				$page->setConfig('next','下一页');
				$page_str = $page->show();
				$limit=$page->firstRow.','.$page->listRows;
				$list=$userModel->likeGet($where,$limit);
			}
			$this->assign('page',$page_str);
			$this->assign('list',$list);
			$this->assign('like',$this->like);

			$this->display();

		} 
		public function Status(){
			$id=$_GET['id'];
			$status=$_GET['status'];
			$userModel=D('User');
			$res=$userModel->change($status,$id);
			$this->redirect('User/index');
		}
		public function del(){
			$model=D('User');
			$id=$_GET['id'];
			$res=$model->deleted($id);
			if($res){
				$this->success('删除成功',U('User/index'),2);
			}else{
				$this->error('登录错误',U('User/index'));
			}

		}
		public function reset(){
			$id=$_GET['id'];
			$model=M('User');
			$pwd=123456;
			$data['pwd']=md5($pwd);
			$list=$model->where("id=".$id)->find();
			if($data['pwd']==$list['pwd']){
				$this->success('重置成功',U('User/index'),2);

			}else{
				$res=$model->where("id=".$id)->save($data);
				$this->success('重置成功',U('User/index'),2);
			}
		}		
	}